package com.zhiyou100.login;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.TreeSet;

/**
 * @packageName: ${NAME}
 * @className: ${PACKAGE_NAME}
 * @Description: TODO 获取登陆人数
 * @author: yang
 * @date: 7/24/20
 */
@WebServlet(name = "getLoginNumber", urlPatterns = "/ajax/getLoginNumber")
public class GetLoginNumber extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        // 设定编码集
        response.setContentType("text/html;charset=UTF-8");
        // 设定类型
        // 获取
        ServletContext servletContext = request.getServletContext();
        // 获取 登陆人数 属性
        TreeSet<String> loginNumber = (TreeSet<String>) servletContext.getAttribute("loginNumber");
        response.getWriter().write(loginNumber.size()+"");

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
